use std::{fs::File, io::Read};

pub fn open_file(file_path: &str) -> Result<String, std::io::Error> {
    let mut file = File::open(file_path)?;
    let mut content = String::new();
    file.read_to_string(&mut content)?;
    Ok(content)
}

macro_rules! insert_into_map {
    ($map: ident, $($key:expr => $value:expr),*) => {
       $(
        $map.insert($key, $value);
       )*
    };
}

#[cfg(test)]
mod tests {
    use std::collections::HashMap;

    use super::*;

    #[test]
    fn read_from_file() {
        let result = open_file("/home/lib/rust-pro/rust-course/ch05/src/test.txt");
        println!("{:?}", result);
    }

    #[test]
    fn test_insert_map() {
        let mut map = HashMap::<String, String>::new();

        insert_into_map!(map, "key1".to_string() => "value1".to_string());
        insert_into_map!(map, "key2".to_string() => "value2".to_string());
        println!("{:?}", map);
    }
}
